package com.dddpeter.yater;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import java.util.ArrayList;
import java.util.Iterator;

public class FlowerView extends View {
	public int flowerType;
	
	public int getFlowerType() {
		return flowerType;
	}

	public void setFlowerType(int flowerType) {
		this.flowerType = flowerType;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Flower f=new Flower();
		
		f.setFlowerType(flowerType);
		f.setX(event.getX());
		f.setY(event.getY());
		this.list.add(f);
		this.invalidate();
		return super.onTouchEvent(event);
	}

	Bitmap back;
	ArrayList list=new ArrayList();
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		Paint paint=new Paint();
		canvas.drawBitmap(back, 0, 0, paint);
		Iterator it=this.list.iterator();
		
		while(it.hasNext()){
			Flower flower=(Flower) it.next();			
			canvas.drawBitmap(BitmapFactory.decodeResource(this.getResources(),flower.getFlowerType()), flower.getX(), flower.getY(), paint);
		}
	}

	public FlowerView(Context context, AttributeSet attrs) {
		super(context, attrs);
		back=BitmapFactory.decodeResource(context.getResources(), R.drawable.caodi);
		this.setFocusable(true);
		
	}
	

}
